package com.spic.business.registrationform.controller;

import com.spic.business.registrationform.domain.ArchiveStaffPostholdersRecords;
import com.spic.business.registrationform.service.IArchiveStaffPostholdersRecordsService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 三项岗位人员安全培训、考核记录Controller
 * 
 * @author spic
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/postholders/records")
public class ArchiveStaffPostholdersRecordsController extends BaseController
{
    @Autowired
    private IArchiveStaffPostholdersRecordsService archiveStaffPostholdersRecordsService;

    /**
     * 查询三项岗位人员安全培训、考核记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArchiveStaffPostholdersRecords archiveStaffPostholdersRecords)
    {
        startPage();
        List<ArchiveStaffPostholdersRecords> list = archiveStaffPostholdersRecordsService.selectArchiveStaffPostholdersRecordsList(archiveStaffPostholdersRecords);
        return getDataTable(list);
    }

    /**
     * 导出三项岗位人员安全培训、考核记录列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveStaffPostholdersRecords archiveStaffPostholdersRecords) throws IOException {
        List<ArchiveStaffPostholdersRecords> list = archiveStaffPostholdersRecordsService.selectArchiveStaffPostholdersRecordsList(archiveStaffPostholdersRecords);
        ExcelUtil<ArchiveStaffPostholdersRecords> util = new ExcelUtil<ArchiveStaffPostholdersRecords>(ArchiveStaffPostholdersRecords.class);
        util.exportExcel(response, list, "三项岗位人员安全培训、考核记录数据");
    }

    /**
     * 获取三项岗位人员安全培训、考核记录详细信息
     */
    @GetMapping(value = "/{studyId}")
    public AjaxResult getInfo(@PathVariable("studyId") Long studyId)
    {
        return AjaxResult.success(archiveStaffPostholdersRecordsService.selectArchiveStaffPostholdersRecordsByStudyId(studyId));
    }

    /**
     * 新增三项岗位人员安全培训、考核记录
     */
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveStaffPostholdersRecords archiveStaffPostholdersRecords)
    {
        return toAjax(archiveStaffPostholdersRecordsService.insertArchiveStaffPostholdersRecords(archiveStaffPostholdersRecords));
    }

    /**
     * 修改三项岗位人员安全培训、考核记录
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveStaffPostholdersRecords archiveStaffPostholdersRecords)
    {
        return toAjax(archiveStaffPostholdersRecordsService.updateArchiveStaffPostholdersRecords(archiveStaffPostholdersRecords));
    }

    /**
     * 删除三项岗位人员安全培训、考核记录
     */
	@DeleteMapping("/{studyIds}")
    public AjaxResult remove(@PathVariable Long[] studyIds)
    {
        return toAjax(archiveStaffPostholdersRecordsService.deleteArchiveStaffPostholdersRecordsByStudyIds(studyIds));
    }
}
